package com.scfw.test;

import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.context.embedded.LocalServerPort;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.junit4.SpringRunner;

import java.net.MalformedURLException;
import java.net.URL;

/**
 * Created by sehuaqi on 2017/7/1.
 */
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@SpringBootConfiguration
public class HelloControllerIT {

    @LocalServerPort
    private String port;

    private URL base;

    @Autowired
    private TestRestTemplate testRestTemplate;

    @Before
    public void setUp(){
        try {
            this.base = new URL("http://localhost" + port + "/");
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
    }

    @Test
    public void getHello(){
        System.out.println("单元测试代码");
        //ResponseEntity<String> response = testRestTemplate.getForEntity(base.toString(),String.class);
        //assertThat(response.getBody(), equalTo("Greetings from Spring Boot!"));
    }

}
